package kuaidi.view.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import kuaidi.entity.kuaidijieguo.kefu.KeFu;
import kuaidi.helper.R;

public class KeFuActivity extends AppCompatActivity {

    @BindView(R.id.info_company_iv)
    ImageView infoCompanyIv;
    @BindView(R.id.info_company_tv)
    TextView infoCompanyTv;
    @BindView(R.id.info_phone_tv)
    TextView infoPhoneTv;
    @BindView(R.id.info_call_ll)
    LinearLayout infoCallLl;
    KeFu keFu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ke_fu);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        keFu = (KeFu) getIntent().getSerializableExtra("info");
        Glide.with(this).load(keFu.getUrl()).into(infoCompanyIv);
        infoCompanyTv.setText(keFu.getName());
        infoPhoneTv.setText(keFu.getPhone());
    }

    @OnClick(R.id.info_call_ll)
    public void onClick() {

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling

            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + keFu.getPhone()));//直接拨打电话
        startActivity(dialIntent);
    }
}
